package com.farewell.controller;

import com.farewell.pojo.Product;
import com.farewell.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author Farewell
 * @date 2021/3/23
 */
@Controller
public class IndexController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/pages/product-list.jsp")
    public ModelAndView product() {
        ModelAndView mv = new ModelAndView();
        PageHelper.startPage(1, 10);
        List<Product> productList = productService.findAll();
        PageInfo<Product> pageInfo = new PageInfo<Product>(productList);
        mv.addObject("pageInfo", pageInfo);
        mv.setViewName("product-list");
        return mv;
    }
}
